package com.xiaojiezhu.netty.base.protocol;


import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

/**
 * 作者 zxj<br>
 * 时间 2017/7/14 17:40
 * 说明 ...
 */
public class Client {
    public static void main(String[] args) {
        new Client().start("localhost",8898);
    }

    private void start(String host,int port){
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        Bootstrap bootstrap = new Bootstrap();

        bootstrap.group(workerGroup);
        bootstrap.channel(NioSocketChannel.class);
        //bootstrap.option(ChannelOption.SO_KEEPALIVE,true);
        bootstrap.handler(new DefaultClientChannelHandler());

        try {
            Channel channel = bootstrap.connect(host, port).sync().channel();
            channel.closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            workerGroup.shutdownGracefully();
        }
    }
}
